function getRandomColor() {
  const rgb = []
  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length == 1 ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}

Page({
  onReady(res) {
    this.videoContext = wx.createVideoContext('myVideo'),
      this.selectComponent('#tabs').resize();
  },
  inputValue: '',
  data: {
    radio: true,
    vid: 'q3260up7sux',
    playerid: 'txv1',
    active: 1,
    src: '',
    imageURL: "https://www.hualigs.cn/image/60b5f056453e7.jpg",
    danmuList: [
      {
        text: '反炸校园,你我同行',
        color: '#ff0000',
        time: 1
      },
      {
        text: '反炸校园,你我同行',
        color: '#ff00ff',
        time: 3
      }]
  },
  onLoad: function (options) {
    // var json = "";
    // var that = this;
    // var jsonStr = options.playerStr;
    // jsonStr = jsonStr.replace(" ", "");
    // console.log("jsonStr", jsonStr);
    // if (typeof jsonStr != 'object') {
    //   jsonStr = jsonStr.replace(/\ufeff/g, "");//重点
    //   json = JSON.parse(jsonStr);
    //   console.log("json对象", json);
    // }

    // if (json.vid != "" && json.vid != null) {
    //   this.setData({
    //     vid: json.vid,
    //     playerid: json.infoId
    //   })
    // }

  },


  bindInputBlur(e) {
    this.inputValue = e.detail.value
  },
  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },

  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  },
  onChange(event) {
    this.setData({
      radio: event.detail,
    });
  },
  submit() {
    wx.switchTab({
      url: '/pages/index/index',
      success: (result) => {
        wx.showToast({
          title: '提交成功',
          icon: 'success',
          duration: 1500
        })
      },
      fail: () => { },
      complete: () => { }
    });

  }

})
